package com.arlen.security_oauth2_1.utils;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import java.util.*;

public class MyAuthUtils {
    public static final List<GrantedAuthority> NO_AUTHORITIES = Collections.emptyList();

    public MyAuthUtils() {
    }

    public static List<GrantedAuthority> commaSeparatedStringToAuthorityList(String authorityString) {
        return createAuthorityList(StringUtils.tokenizeToStringArray(authorityString, ","));
    }

    public static Set<String> authorityListToSet(Collection<? extends GrantedAuthority> userAuthorities) {
        Assert.notNull(userAuthorities, "userAuthorities cannot be null");
        Set<String> set = new HashSet(userAuthorities.size());
        Iterator var2 = userAuthorities.iterator();

        while(var2.hasNext()) {
            GrantedAuthority authority = (GrantedAuthority)var2.next();
            set.add(authority.getAuthority());
        }

        return set;
    }

    public static List<GrantedAuthority> createAuthorityList(String... authorities) {
        List<GrantedAuthority> grantedAuthorities = new ArrayList(authorities.length);
        String[] var2 = authorities;
        int var3 = authorities.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            String authority = var2[var4];
            grantedAuthorities.add(new SimpleGrantedAuthority(authority));
        }

        return grantedAuthorities;
    }
}
